package cn.itcast.listener;

import cn.itcast.domain.system.User;
import cn.itcast.utils.MailUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class EmailListener implements MessageListener {

    private ObjectMapper objectMapper = new ObjectMapper();


    @Override
    public void onMessage(Message message) {
        try {
            //1. 读取消息
            byte[] body = message.getBody();
            //2. 把消息转换为java对象
            User user = objectMapper.readValue(body, User.class);
            //3. 处理消息
        /*
            sendMsg(String to, String subject, String content)
                    to： 发送给谁（邮件的接受者）
                    subject: 邮件的主题
                    content: 邮件的正文内容
*/
            MailUtil.sendMsg(user.getEmail(),"您的saas-export账号已经开通","恭喜您，您的账号已经开通，以后只有007，没有996");
            System.out.println("发送邮件成功...");
        } catch (Exception e) {
            e.printStackTrace();

        }

    }
}
